<?php
class DoanphicbsController extends AppController {

	var $name = 'Doanphicbs';

	function index() {
		$this->Doanphicb->recursive = 0;
		$this->set('doanphicbs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid doanphicb', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('doanphicb', $this->Doanphicb->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Doanphicb->create();
			if ($this->Doanphicb->save($this->data)) {
				$this->Session->setFlash(__('The doanphicb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The doanphicb could not be saved. Please, try again.', true));
			}
		}
		$thangs = $this->Doanphicb->Thang->find('list');
		$this->set(compact('thangs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid doanphicb', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Doanphicb->save($this->data)) {
				$this->Session->setFlash(__('The doanphicb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The doanphicb could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Doanphicb->read(null, $id);
		}
		$thangs = $this->Doanphicb->Thang->find('list');
		$this->set(compact('thangs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for doanphicb', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Doanphicb->delete($id)) {
			$this->Session->setFlash(__('Doanphicb deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Doanphicb was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
